//
//  OPForum.h
//  OPFramework
//
//  Created by malcom on 7/12/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "OPBaseObject.h"
#import "OPUser.h"
#import "OPPageContainer.h"
#import "OPTopic.h"

/*!
    @enum		OPForum_Type
    @abstract   This key contains the possible return value for OPForum_ForumType property
    @constant   OPForum_Type_Category		it's a category forum (does not contains topics)
	@constant	OPForum_Type_NormalForum	it's a normal forum that contains topics
	@constant	OPForum_Type_Link			it's a forum link (does not contains forum, it's referred to a specified url address
*/

typedef enum OPForum_Type {
    OPForum_Type_Category		= 0,
    OPForum_Type_NormalForum	= 1,
	OPForum_Type_Link			= 2
} OPForum_Type;


/*!
 @class			OPForum
 @abstract		This forum represent a forum object.
 @discussion	A forum contains some properties (look at <i>-getPropertyForKey:</i> method),some childs (you can access to <i>_childs</i> property), <br/>
				the list of cached pages (the cache is managed automatically, you can access to the list of topics for a specific page using <br/>
				<i>-getTopicsAtPage:useCache:</i> method), <i>_forumID</i> (the forum unique id as integer), <i>_topicsNumber</i> (number of topics into the forum), <br/>
				<i>_totalPages</i> (number of pages according to your board settings) and <i>_forumPassword</i> (you should setup it if the forum is password protected). <br/>
 */


@class OPTopic;
@interface OPForum : OPBaseObject {
	NSMutableArray			*_childs;			// childs forums
	NSString				*_forumPassword;	// setup if is a password protected forum
	
	int						_forumID;			// forum id
	OPPageContainer			*_forumPages;		// pages container
	
	// FORUM PROPERTIES
	NSString				*p_forumName;		// forum name
	NSDate					*p_lastPostDate;	// last post date
	NSNumber				*p_postsNumber;		// number of forum's posts
	NSNumber				*p_topicsNumber;	// number of topic's posts
	NSNumber				*p_forumType;		// forum type
	OPForum					*p_parentForum;		// parent forum
	NSData					*p_forumIcon;		// forum image icon
	OPUser					*p_lastPoster;		// forum last poster
	NSString				*p_lastPostSubject;	// forum last post subject
	NSNumber				*p_lastPostID;		// forum last post ID
	
	NSNumber				*p_newTopicsSinceLogin;			// number of new topics since login date
	NSNumber				*p_updatedTopicsSinceLogin;		// number of updated topics since login date
	
}

@property (readonly)	int						 _forumID;
@property (readonly)	OPPageContainer			*_forumPages;
@property (assign)		NSMutableArray			*_childs;
@property (assign)		NSString				*_forumPassword;
@property (assign)		NSString				*p_forumName;		// forum name
@property (assign)		NSDate					*p_lastPostDate;	// last post date
@property (assign)		NSNumber				*p_postsNumber;		// number of forum's posts
@property (assign)		NSNumber				*p_topicsNumber;	// number of topic's posts
@property (assign)		NSNumber				*p_forumType;		// forum type
@property (assign)		OPForum					*p_parentForum;		// parent forum
@property (assign)		NSData					*p_forumIcon;		// forum image icon
@property (assign)		OPUser					*p_lastPoster;		// forum last poster
@property (assign)		NSString				*p_lastPostSubject;	// forum last post subject
@property (assign)		NSNumber				*p_lastPostID;		// forum last post ID
@property (readonly)	NSNumber				*p_newTopicsSinceLogin;	
@property (readonly)	NSNumber				*p_updatedTopicsSinceLogin;	

#pragma mark INIT

/*!
    @method     initWithForumID:ofBoard:
    @abstract   <b>You should not use this method (you don't need to init a OPForum object)</b><br/>
				This object init a new OPForum object class without any other additional data (all variables are empty).
				This method is only used by OPBoardStructure in order to perform the _rootNode object creation.
    @param		_idforum the forum id to associate
	@param		_board the parent board of the forum
*/


- (id) initWithForumID:(int) _idforum ofBoard:(OPBoard *) _board;

/*!
    @method     initByLoadingPropertiesDictionary:fromBoard:
    @abstract   <b>You should not use this method (you don't need to init a OPForum object)</b><br/>
				This method init a new forum object with the response dictionary of an XML-RPC response.
				This method is used by OPBoardStructure in order to perform tree creation.
	@param		_dict the data with the properties of this forum
	@param		_board the parent board of the forum
*/

- (id) initByLoadingPropertiesDictionary:(NSDictionary *) _dict fromBoard:(OPBoard *) _board;

#pragma mark GET


/*!
    @method		getTopicsAtPage:cached:
    @abstract   Return loaded topics for given page (in synchronous mode) or nil (in asynchronous)
    @discussion This method allows you to get an NSArray with the list of OPTopic objects relative to specified page. <br/>
				See results node to get more informations. 
	@param		_pgIdx the index of page to get (<i>_forumPages</i> property contains the number of pages available for this topic) <br/>
	@param		_useCache if you specify YES OFAPI try to use the cached informations if available (NO will perform a new forced request) <br/>
	@result		This method return an NSArray with the list of topics for specified page if you are using it in sync mode. <br/>
				If you are using OFAPI framework in async mode this method return a nil object and the result will be available listener classes <br/>
				throught the method <i>-dataUpdatedFor:forMethod:</i> when the class will receive requested data. (see OPBoard class documentation for more <br/>
				infos about the async mode). <br/> 
*/

- (NSArray *) getTopicsAtPage:(NSNumber *) _pgIdx;
- (OPTopic *) getCachedTopicWithID:(NSNumber *) _id;
- (NSArray *) getModerators;

#pragma mark PRIVATE METHODS
- (void) _loadForumProperties:(NSDictionary *) _dic;
- (void) _parseLoadTopicsAtPageRequest:(NSArray *) _results;
- (void) _parseRefreshForumProperties:(NSArray *) _result;

@end
